package com.yangzc.lion.sys.config.load;

import java.io.File;
import java.util.List;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;

import com.yangzc.lion.sys.framework.util.ConfigLocationsUtil;

public class MinfwHibernateSessionFactoryBean extends LocalSessionFactoryBean {
	private static final Logger LOGGER = Logger
			.getLogger(MinfwHibernateSessionFactoryBean.class);

	@Override
	public void setDataSource(DataSource dataSource) {
		super.setDataSource(dataSource);
		init();
	}

	public void init() {
		List<File> cfg_arr = ConfigLocationsUtil.getConfigLocationList(
				ConfigLocationsUtil.getWebContentPath(), "hibernate.xml");
		Resource[] resource = new Resource[cfg_arr.size()];
		for (int i = 0; i < cfg_arr.size(); i++) {
			resource[i] = new FileSystemResource(cfg_arr.get(i));
		}
		this.setConfigLocations(resource);
	}
}
